package com.szpx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szpx.entity.Film;
import com.szpx.entity.FilmInformation;
import com.szpx.service.FilmInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class FilmInformationController {

    @Autowired
    private FilmInformationService filmInformationService;

    @GetMapping("/selectFinformationById/{id}")
    public String selectFinformation(@PathVariable("id") Integer id, Model model) {
        FilmInformation filmInformation = filmInformationService.selectFinformationmById(id);
        if (filmInformation != null){
            model.addAttribute("filmInformation",filmInformation);
            return "chw/chw_FilmInformationHtml/chw_FilmInformation";
        }else {
            return null;
        }
    }

    /**
     * 多条件分页查询所有影片
     */
    @GetMapping("/ilist")
    public String getFInlist(
            @RequestParam(defaultValue = "1") int pno,
            @RequestParam(defaultValue = "10") int pageSize,
            FilmInformation filmInformation, Model model){
        PageHelper.startPage(pno,pageSize);//开始分页
        List<FilmInformation> ilist = filmInformationService.getListByMation(filmInformation);
        PageInfo<FilmInformation> page = new PageInfo<FilmInformation>(ilist);
        model.addAttribute("ilist",ilist); //将查询到的数据放入model对象中
        model.addAttribute("page",page);
        model.addAttribute("finfor",filmInformation.getFinfor());
        model.addAttribute("score",filmInformation.getScore());
        model.addAttribute("pno",pno);
        return "chw/chw_FilmInformationHtml/chw_FilmInformationIist";
    }

}
